package com.ny.view;

import com.ny.entity.Manager;
import com.ny.entity.Stud;
import com.ny.service.ManagerService;
import com.ny.service.StudentService;
import com.ny.service.impl.StudentServiceImpl;
import com.ny.service.impl.ManagerServiceImpl;

import java.sql.SQLException;
import java.util.Scanner;

public class
ViewMain {
    private static StudentService uer;
    private static ManagerService  uer1 ;


    public static void main(String[] args) throws ClassNotFoundException, SQLException, SQLException {
        uer = new StudentServiceImpl();
        uer1 = new ManagerServiceImpl();
        System.out.println("用户系统");
        boolean f = true;
        while (f) {
            System.out.println("欢迎来到校园商品售卖系统");
            System.out.println("请选择项目");
            System.out.println("1.用户登录");
            System.out.println("2.管理员登录");
            System.out.println("3.注册账号");
            System.out.println("0.退出系统");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("请输入用户名");
                    String name = scanner.next();
                    System.out.println("请输入密码");
                    String password = scanner.next();
                    Stud stud = uer.log(name, password);
                    if (stud != null) {
                        System.out.println("登录成功");
                        InterView interView = new InterView();
                        interView.indexview(stud);
                    } else {
                        System.out.println("登录失败");
                    }
                    break;
                case 2:
                    System.out.println("管理员登录");
                    System.out.println("请输入管理员用户名");
                    String name1 = scanner.next();
                    System.out.println("请输入管理员密码");
                    String pwd1 = scanner.next();
                    Manager man = uer1.log(name1, pwd1);
                    if (man != null) {
                            System.out.println("登录成功");
                            ManagerView managerView = new ManagerView();
                            managerView.showManagerView();
                    } else {
                            System.out.println("登录失败");
                    }

                    break;
                case 3:
                    System.out.println("注册账号");
                    ReguserView  reguserView = new ReguserView();
                    reguserView.showRegisterForm();
                    return;
                case  0:
                    System.out.println("0.退出");
                    break;

                default:
                    System.out.println("未知选项,请输入正确选项");
                break;

            }

            f = false;
            scanner.close();
        }
    }
}
